package de.timoh.standardchatplugin;

import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.Event.Priority;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;

/**
 * Mainklasse des Plugins.
 *
 * @version 0.1
 * @author Timo
 */


public class StandardChatPlugin extends JavaPlugin{
    private final ChatPlayerListener playerListener = new ChatPlayerListener(this);


    public void onEnable() {
        PluginManager pm = getServer().getPluginManager();
        PlayerHandler.load(this);
        pm.registerEvent(Event.Type.PLAYER_COMMAND_PREPROCESS, playerListener, Priority.Normal, this);
        pm.registerEvent(Event.Type.PLAYER_JOIN, playerListener, Priority.Normal, this);
        PluginDescriptionFile pdfFile = this.getDescription();
        System.out.println( pdfFile.getName() + " version " + pdfFile.getVersion() + " wurde erfolgreich initialisiert!" );

    }

    public void onDisable() {
        
    }

    public boolean isPlayerOnServer(String name){
        return PlayerEx.isPlayerInMap(name);
    }

    public boolean isPlayerOnline(String name){
        Player [] onlinePlayers = getServer().getOnlinePlayers();
        for(int i = 0; i < onlinePlayers.length; i++){
            if(onlinePlayers[i].getName().equals(name))return true;
        }
        return false;
    }

    public boolean hasRank(String name, int rank){
        return PlayerEx.getPlayer(name).getRank() == rank;
    }

    public int getRank(String name){
        return PlayerEx.getPlayer(name).getRank();
    }

    public void performBackup(){
        PlayerEx.saveAsTXT();
    }
}
